package com.alvin.demo.config;

import com.alvin.demo.job.MyJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail jobDetail(){
        return JobBuilder.newJob(MyJob.class)
                .storeDurably() // 持久化
                .withIdentity("MyJob" , "MyJob-Group1")
                .usingJobData("count" , 1)
                .build();
    }

    @Bean
    public Trigger trigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("MyTrigger1" , "MyJob-Group1")
                .forJob(jobDetail())
                .withSchedule(
                        CronScheduleBuilder.cronSchedule(
                                "0/2 * * * * ? *"
                        ))
                .build() ;
    }
}
